package top.lingkang.utils;

import com.badlogic.gdx.physics.box2d.*;
import top.lingkang.constants.FixtureDefType;

public class BodyUtils {

    /**
     * 往世界中创建一个物体--地面
     */
    public static Body createGroundBody(float x, float y, float width, float height, World world) {
        // 创建一个地面，其实是一个静态物体，这里我们叫它地面，玩家可以走在上面
        BodyDef groundBodyDef = new BodyDef();
        groundBodyDef.type = BodyDef.BodyType.StaticBody;// 静态的质量为0
        groundBodyDef.position.x = x;// 位置
        groundBodyDef.position.y = y;
        // 创建这个地面的身体，我们对这个物体
        Body body = world.createBody(groundBodyDef);
        PolygonShape groundBox = new PolygonShape();// 物体的形状，这样创建是矩形的
        groundBox.setAsBox(width, height);// 物体的宽高
        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = groundBox;
        fixtureDef.filter.categoryBits = FixtureDefType.GROUND;
        fixtureDef.density = 0;// 静态物体的质量应该设为0
        body.createFixture(fixtureDef);
        return body;
    }
}
